package com.wx.service;


import com.wx.entity.ImageTypeEntity;
import com.wx.entity.NotFonudMsgBack;
import com.wx.entity.TextTypeEntity;
import com.wx.util.BaseUtil;
import com.wx.util.XmlUtil;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @ClassName TestServiceType
 * @Author Administrator
 * @Date 2018/12/30 15:35
 * @Version 1.0
 * @Description 处理文本类型的消息
 **/
@Service("textServiceType")
public class TextServiceType {
    private static final String MENU="名言";
    // 处理文本消息
    public String handlealltext(Map stringMap){
        String toUserName = (String) stringMap.get("ToUserName");
        String fromUserName = (String) stringMap.get("FromUserName");
        String content = (String) stringMap.get("Content");
        String msgId = (String) stringMap.get("MsgId");

        String newTime= BaseUtil.getBaseUtil().getIntegerTime();
        TextTypeEntity entity=new TextTypeEntity();
        entity.setToUserName(fromUserName);
        entity.setFromUserName(toUserName);
        entity.setCreatetime(newTime);
        entity.setMsgType("text");
        if (MENU.equals(content)){
            entity.setContent("人有三大特征——鸽子，真香，复读机，所以你懂我意思吧！");
        }else {
            entity.setContent(content);
        }
        System.out.println(JSONObject.fromObject(entity));
        return XmlUtil.getXmlUtil().ReturnMsg(entity);
    }
    // 处理关注事件（回复文本）
    public String event(Map map) {
        String toUserName = (String) map.get("ToUserName");
        String fromUserName = (String) map.get("FromUserName");
        String content = (String) map.get("Content");
        String msgId = (String) map.get("MsgId");

        String newTime= BaseUtil.getBaseUtil().getIntegerTime();
        TextTypeEntity entity=new TextTypeEntity();
        entity.setToUserName(fromUserName);
        entity.setFromUserName(toUserName);
        entity.setCreatetime(newTime);
        entity.setMsgType("text");
        entity.setContent("非常幸运你来了！尝试回复“名言”见识人生哲理！");
        return XmlUtil.getXmlUtil().ReturnMsg(entity);
    }
    // 处理菜单栏点击事件
    public String click(Map map) {
        String toUserName = (String) map.get("ToUserName");
        String fromUserName = (String) map.get("FromUserName");
        String MsgType = (String) map.get("MsgType");
        String EventKey = (String) map.get("EventKey");

        String newTime = BaseUtil.getBaseUtil().getIntegerTime();
        TextTypeEntity entity = new TextTypeEntity();
        entity.setToUserName(fromUserName);
        entity.setFromUserName(toUserName);
        entity.setCreatetime(newTime);
        entity.setMsgType("text");
        entity.setContent(map.get("EventKey") + "");
        return XmlUtil.getXmlUtil().ReturnMsg(entity);
    }
    //处理图片消息
    public String Imagemsg(Map map) {
        String toUserName = (String) map.get("ToUserName");
        String fromUserName = (String) map.get("FromUserName");
        String MsgType = (String) map.get("MsgType");
        String picUrl = (String) map.get("PicUrl");
        String MediaId = (String) map.get("MediaId");

        String newTime = BaseUtil.getBaseUtil().getIntegerTime();
        ImageTypeEntity entity = new ImageTypeEntity();
        entity.setToUserName(fromUserName);
        entity.setFromUserName(toUserName);
        entity.setCreatetime(newTime);
        entity.setMsgType(MsgType);
        entity.setPicUrl(picUrl);
        entity.setMediaId(MediaId);
        System.out.println(JSONObject.fromObject(entity));
        return XmlUtil.getXmlUtil().ReturnImage(entity);
    }
}
